package com.zhou.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhou.zhxy.mapper.GradeMapper;
import com.zhou.zhxy.pojo.Grade;
import com.zhou.zhxy.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service  初始化 可以指定当前的实现类
 * Transactional  事务
 */
@Service("gradeServiceImpl")
@Transactional
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    @Override
    public List<Grade> getGradeList() {
        return baseMapper.selectList(null);
    }

    @Override
    public IPage<Grade> getGradeLists(Page<Grade> page, Grade grade) {
        QueryWrapper queryWrapper = null;
        if(grade != null){
            queryWrapper = new QueryWrapper<>();
            if(grade.getName() != null){
                queryWrapper.eq("name",grade.getName());
            }
            queryWrapper.orderByDesc("id");
            queryWrapper.orderByAsc("name");
        }
        IPage<Grade> iPage = baseMapper.selectPage(page,queryWrapper);
        return iPage;
    }
}
